<template>
  <view v-if="show" class="modal">
    <view class="modal-content">
      <text class="modal-title">自我效果评价</text>
      <view class="rating-options">
        <button @click="submitRating(1)" :class="{'selected': rating === 1}" class="rating-button">一般</button>
        <button @click="submitRating(2)" :class="{'selected': rating === 2}" class="rating-button">较好</button>
        <button @click="submitRating(3)" :class="{'selected': rating === 3}" class="rating-button">非常好</button>
      </view>
      <view class="suggestion-box">
        <textarea v-model="suggestion" placeholder="请输入您的建议（非必填）" class="suggestion-textarea"></textarea>
        <!-- <button @touchstart="startRecording" @touchend="stopRecording" class="voice-input-button">按住说话</button> -->
      </view>
      <button @click="submit" class="submit-button">提交</button>
    </view>
  </view>
</template>

<script>
export default {
  props: ['show'],
  data() {
    return {
      rating: null,
      suggestion: '',
      recognition: null
    };
  },
  methods: {
    submitRating(rating) {
      this.rating = rating;
    },
    startRecording() {
      if ('webkitSpeechRecognition' in window) {
        this.recognition = new webkitSpeechRecognition();
        this.recognition.continuous = false;
        this.recognition.interimResults = false;
        this.recognition.lang = 'zh-CN';
        this.recognition.onresult = (event) => {
          this.suggestion = event.results[0][0].transcript;
        };
        this.recognition.start();
      } else {
        alert('您的浏览器不支持语音识别');
      }
    },
    stopRecording() {
      if (this.recognition) {
        this.recognition.stop();
      }
    },
    submit() {
      this.$emit('submit-rating', { rating: this.rating, suggestion: this.suggestion });
    }
  }
};
</script>

<style scoped>
.modal {
	 z-index: 1000;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

.modal-content {
  background: #fff;
  padding: 30px;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
  max-width: 90%;
  width: 400px;
}

.modal-title {
  font-size: 24px;
  margin-bottom: 20px;
  color: #333;
}

.rating-options {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.rating-button {
  margin: 0 10px;
  padding: 12px 24px;
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s ease;
  font-size: 16px;
}

.rating-button:hover {
  background: #0056b3;
}

.rating-button.selected {
  background: #0056b3;
}

.suggestion-box {
  margin-bottom: 20px;
}

.suggestion-textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  resize: vertical;
  font-size: 16px;
  margin-bottom: 10px;
}

.voice-input-button {
  padding: 12px 24px;
  background: #f0f0f0;
  color: #333;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s ease;
  font-size: 16px;
}

.voice-input-button:hover {
  background: #ddd;
}

.submit-button {
  padding: 12px 24px;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s ease;
  font-size: 16px;
}

.submit-button:hover {
  background: #218838;
}
</style>